package net.board.action;

import java.io.PrintWriter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.board.db.*;

public class BoardDeleteAction implements Action {
	 public ActionForward execute(HttpServletRequest request,HttpServletResponse response) 
	 	throws Exception{
		 
		ActionForward forward = new ActionForward();
		
		request.setCharacterEncoding("UTF-8");
		response.setCharacterEncoding("UTF-8");
		response.setContentType("text/html; charset=UTF-8");
		
		int number = Integer.parseInt(request.getParameter("number"));
	   	boolean result=false;
	   	boolean usercheck=false;
	   	int ID=Integer.parseInt(request.getParameter("ID"));
	   	
	   	BoardDAO boarddao=new BoardDAO();
	   	usercheck=boarddao.isBoardWriter(ID, request.getParameter("QNA_PASS"));
	   	
	   	if(usercheck==false){
	   		response.setContentType("text/html;charset=utf-8");
	   		PrintWriter out=response.getWriter();
	   		out.println("<script>");
	   		out.println("alert('パスワードが違います。');");
	   		out.println("location.href='./BoardList.bo?number="+number+"';");
	   		out.println("</script>");
	   		out.close();
	   		return null;
	   	}
	   	
	   	result=boarddao.boardDelete(ID);
	   	if(result==false){

	   		return null;
	   	}
	   	
	   	forward.setRedirect(true);
   		forward.setPath("./BoardList.bo?number="+number);
   		return forward;
	 }
}